package com.wyvoid.forum.web.action;

import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.integration.spring.SpringBean;
import com.wyvoid.forum.domain.Forum;
import com.wyvoid.forum.domain.User;
import com.wyvoid.forum.service.IUserService;
import com.wyvoid.forum.service.IForumService;
import com.wyvoid.forum.service.ITopicService;
import com.wyvoid.forum.service.IPostService;
import com.wyvoid.forum.annotations.Secure;

import java.util.List;
import java.util.HashMap;


/**
 * <p>51void.com</p>
 * User:cjp
 * Date: 2007-5-13
 * Time: 20:30:23
 */
@UrlBinding(value = "/index.do")
@Secure(authority = "canViewForum")
public class IndexAction extends BaseAction {
    private HashMap<Long,List> forums;
    private List<Forum> groupForums;
    @SpringBean
    private IForumService forumService;
    @SpringBean
    private IUserService userService;
    @SpringBean
    private ITopicService topicService;
    @SpringBean
    private IPostService postService;
    private long countUser;
    private long countTopic;
    private long countPost;

    // 最新注册的用户
    private User newestUser;

    private long groupId;


    public HashMap<Long, List> getForums() {
        return forums;
    }

    public List<Forum> getGroupForums() {
        return groupForums;
    }

    public void setForumService(IForumService forumService) {
        this.forumService = forumService;
    }

    public void setUserService(IUserService userService) {
        this.userService = userService;
    }

    public void setTopicService(ITopicService topicService) {
        this.topicService = topicService;
    }

    public void setPostService(IPostService postService) {
        this.postService = postService;
    }

    public User getNewestUser() {
        return newestUser;
    }

    public long getCountUser() {
        return countUser;
    }

    public long getCountTopic() {
        return countTopic;
    }

    public long getCountPost() {
        return countPost;
    }

    public void setGroupId(long groupId) {
        this.groupId = groupId;
    }

    @DefaultHandler
    public Resolution index() {
        forums=new HashMap<Long,List>();
        // 论坛数据
        groupForums=forumService.getGroupForums(groupId);
        for(Forum groupForum:groupForums){
            long groupForumId=groupForum.getId();
            List tempForums=forumService.getValidForums(groupForumId);
            forums.put(groupForumId,tempForums);
        }
        countUser = userService.countUser();
        countTopic = topicService.countTopic();
        countPost = postService.countPost();

        // 最新注册的用户
        newestUser = userService.getNewestUser();
        return getBBSResolution("index");
    }
}
